home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / gnu / cvs-1_3.lha / cvs-1.3 / contrib / cvs_acls.pl < prev    next >
Perl Script  |  1992-04-11  |  5KB  |  143 lines

  1. #!/usr/bin/perl --  # -*-Perl-*-
  2. #
  3. # cvs_acls.pl,v 1.2 1992/04/11 16:01:24 berliner Exp
  4. #
  5. # Access control lists for CVS.  dgg@ksr.com (David G. Grubbs)
  6. #
  7. # CVS "commitinfo" for matching repository names, running the program it finds
  8. # on the same line.  More information is available in the CVS man pages.
  9. #
  10. # ==== INSTALLATION:
  11. #
  12. # To use this program as I intended, do the following four things:
  13. #
  14. # 0. Install PERL.  :-)
  15. #
  16. # 1. Put one line, as the *only* non-comment line, in your commitinfo file:
  17. #
  18. #    DEFAULT        /usr/local/bin/cvs_acls
  19. #
  20. # 2. Install this file as /usr/local/bin/cvs_acls and make it executable.
  21. #
  22. # 3. Create a file named $CVSROOT/CVSROOT/avail.
  23. #
  24. # ==== FORMAT OF THE avail FILE:
  25. #
  26. # The avail file determines whether you may commit files.  It contains lines
  27. # read from top to bottom, keeping track of a single "bit".  The "bit"
  28. # defaults to "on".  It can be turned "off" by "unavail" lines and "on" by
  29. # "avail" lines.  ==> Last one counts.
  30. #
  31. # Any line not beginning with "avail" or "unavail" is ignored.
  32. #
  33. # Lines beginning with "avail" or "unavail" are assumed to be '|'-separated
  34. # triples: (All spaces and tabs are ignored in a line.)
  35. #
  36. #   {avail.*,unavail.*} [| user,user,... [| repos,repos,...]]
  37. #
  38. #    1. String starting with "avail" or "unavail".
  39. #    2. Optional, comma-separated list of usernames.
  40. #    3. Optional, comma-separated list of repository pathnames.
  41. #    These are pathnames relative to $CVSROOT.  They can be directories or
  42. #    filenames.  A directory name allows access to all files and
  43. #    directories below it.
  44. #
  45. # Example:  (Text from the ';;' rightward may not appear in the file.)
  46. #
  47. #    unavail            ;; Make whole repository unavailable.
  48. #    avail|dgg        ;; Except for user "dgg".
  49. #    avail|fred, john|bin/ls    ;; Except when "fred" or "john" commit to
  50. #                ;; the module whose repository is "bin/ls"
  51. #
  52. # PROGRAM LOGIC:
  53. #
  54. #    CVS passes to @ARGV an absolute directory pathname (the repository
  55. #    appended to your $CVSROOT variable), followed by a list of filenames
  56. #    within that directory.
  57. #
  58. #    We walk through the avail file looking for a line that matches both
  59. #    the username and repository.
  60. #
  61. #    A username match is simply the user's name appearing in the second
  62. #    column of the avail line in a space-or-comma separate list.
  63. #
  64. #    A repository match is either:
  65. #        - One element of the third column matches $ARGV[0], or some
  66. #          parent directory of $ARGV[0].
  67. #        - Otherwise *all* file arguments ($ARGV[1..$#ARGV]) must be
  68. #          in the file list in one avail line.
  69. #        - In other words, using directory names in the third column of
  70. #          the avail file allows committing of any file (or group of
  71. #          files in a single commit) in the tree below that directory.
  72. #        - If individual file names are used in the third column of
  73. #          the avail file, then files must be committed individually or
  74. #          all files specified in a single commit must all appear in
  75. #          third column of a single avail line.
  76. #
  77.  
  78. $debug = 0;
  79. $cvsroot = $ENV{'CVSROOT'};
  80. $availfile = $cvsroot . "/CVSROOT/avail";
  81. $myname = $ENV{"USER"} if !($myname = $ENV{"LOGNAME"});
  82.  
  83. eval "print STDERR \$die='Unknown parameter $1\n' if !defined \$$1; \$$1=\$';"
  84.     while ($ARGV[0] =~ /^(\w+)=/ && shift(@ARGV));
  85. exit 255 if $die;        # process any variable=value switches
  86.  
  87. die "Must set CVSROOT\n" if !$cvsroot;
  88. ($repos = shift) =~ s:^$cvsroot/::;
  89. grep($_ = $repos . '/' . $_, @ARGV);
  90.  
  91. print "$$ Repos: $repos\n","$$ ==== ",join("\n$$ ==== ",@ARGV),"\n" if $debug;
  92.  
  93. $exit_val = 0;                # Good Exit value
  94.  
  95. $universal_off = 0;
  96. open (AVAIL, $availfile) || exit(0);    # It is ok for avail file not to exist
  97. while (<AVAIL>) {
  98.     chop;
  99.     next if /^\s*\#/;
  100.     next if /^\s*$/;
  101.     ($flagstr, $u, $m) = split(/[\s,]*\|[\s,]*/, $_);
  102.  
  103.     # Skip anything not starting with "avail" or "unavail" and complain.
  104.     (print "Bad avail line: $_\n"), next
  105.     if ($flagstr !~ /^avail/ && $flagstr !~ /^unavail/);
  106.  
  107.     # Set which bit we are playing with. ('0' is OK == Available).
  108.     $flag = (($& eq "avail") ? 0 : 1);
  109.  
  110.     # If we find a "universal off" flag (i.e. a simple "unavail") remember it
  111.     $universal_off = 1 if ($flag && !$u && !$m);
  112.  
  113.     # $myname considered "in user list" if actually in list or is NULL
  114.     $in_user = (!$u || grep ($_ eq $myname, split(/[\s,]+/,$u)));
  115.     print "$$ \$myname($myname) in user list: $_\n" if $debug && $in_user;
  116.  
  117.     # Module matches if it is a NULL module list in the avail line.  If module
  118.     # list is not null, we check every argument combination.
  119.     if (!($in_repo = !$m)) {
  120.     @tmp = split(/[\s,]+/,$m);
  121.     for $j (@tmp) {
  122.         # If the repos from avail is a parent(or equal) dir of $repos, OK
  123.         $in_repo = 1, last if ($repos eq $j || $repos =~ /^$j\//);
  124.     }
  125.     if (!$in_repo) {
  126.         $in_repo = 1;
  127.         for $j (@ARGV) {
  128.         last if !($in_repo = grep ($_ eq $j, @tmp));
  129.         }
  130.     }
  131.     }
  132.     print "$$ \$repos($repos) in repository list: $_\n" if $debug && $in_repo;
  133.  
  134.     $exit_val = $flag if ($in_user && $in_repo);
  135.     print "$$ ==== \$exit_val = $exit_val\n$$ ==== \$flag = $flag\n" if $debug;
  136. }
  137. close(AVAIL);
  138. print "$$ ==== \$exit_val = $exit_val\n" if $debug;
  139. print "**** Access denied: Insufficient Karma ($myname|$repos)\n" if $exit_val;
  140. print "**** Access allowed: Personal Karma exceeds Environmental Karma.\n"
  141.     if $universal_off && !$exit_val;
  142. exit($exit_val);
  143.